package com.colin.aiyi.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.colin.aiyi.R;
import com.colin.aiyi.entity.User;
import com.colin.aiyi.ui.Home.MainActivity;
import com.colin.aiyi.utils.SharePreferenceUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bingoogolapple.bgabanner.BGABanner;

/**
 * Created by hl on 2017/5/25.
 */

public class GuideAc extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.banner_guide_content)
    BGABanner bannerGuideContent;
    @BindView(R.id.button)
    Button button;
    @BindView(R.id.text1)
    TextView text1;
    @BindView(R.id.text2)
    TextView text2;
    @BindView(R.id.text3)
    TextView text3;
    @BindView(R.id.text4)
    TextView text4;

    List<TextView> list=new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_guide);
        ButterKnife.bind(this);
        bannerGuideContent.setData(R.mipmap.gui1, R.mipmap.gui2, R.mipmap.gui3);
        if (SharePreferenceUtil.getObject(this, User.class) == null) {
            SharePreferenceUtil.saveObject(this, User.getInstance());
        }


        list.add(text1);
        list.add(text2);
        list.add(text3);
        list.add(text4);
        for (TextView textView : list) {
            textView.setOnClickListener(this);
        }
        bannerGuideContent.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                if (position>list.size())
                    position=list.size()-1;
                onClick(list.get(position));
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });





    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.button:
                //if (bannerGuideContent.getCurrentItem() + 1 == bannerGuideContent.getItemCount()) {
                    startActivity(new Intent(this, MainActivity.class));
                    finish();
//                }
                break;
            case R.id.text1:
                setView();
                v.getBackground().setLevel(1);
                break;
            case R.id.text2:
                setView();
                v.getBackground().setLevel(1);
                break;
            case R.id.text3:
                setView();
                v.getBackground().setLevel(1);
                break;
            case R.id.text4:
                setView();
                v.getBackground().setLevel(1);
                break;
        }
    }


    private void setView(){
        text1.getBackground().setLevel(0);
        text2.getBackground().setLevel(0);
        text3.getBackground().setLevel(0);
        text4.getBackground().setLevel(0);
    }
}
